package com.ec.system.modules.sys.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ec.core.common.core.api.ResponseMsg;
import com.ec.core.common.core.api.Result;
import com.ec.core.common.core.base.BasePageVO;
import com.ec.core.log.annotations.OperLog;
import com.ec.core.mybatis.groups.UpdateGroup;
import com.ec.core.secure.annotations.PreAuth;
import com.ec.system.modules.sys.dto.QueryTenantParamDTO;
import com.ec.system.modules.sys.dto.SysTenantParamDTO;
import com.ec.system.modules.sys.entity.SysTenantParam;
import com.ec.system.modules.sys.service.ISysTenantParamService;
import com.ec.system.modules.sys.vo.SysTenantParamVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 租户参数接口
 * @author: Eric Lee
 * @time: 2021/9/22 11:30
 */
@RestController
@RequestMapping("/tenantParam")
public class SysTenantParamController {
    @Resource
    private ISysTenantParamService sysTenantParamService;

    /**
     * 租户分页列表
     *
     * @param dto
     * @return
     */
    @GetMapping("/list")
    @PreAuth("sys_tenantParam_view")
    public Result<BasePageVO<SysTenantParamVO>>listTenantParam(QueryTenantParamDTO dto){

        return ResponseMsg.success(sysTenantParamService.listTenantParamByTenantId(dto.getTenantId(),
                new Page<SysTenantParam>(dto.getPageNo(),dto.getPageSize())));
    }

    /**
     * 添加租户
     *
     * @param sysTenantParamDTO
     * @return
     */
    @PostMapping
    @PreAuth("sys_tenantParam_add")
    @OperLog(desc = "新增租户")
    public Result<Void> addTenantParam(@RequestBody SysTenantParamDTO sysTenantParamDTO){
        return ResponseMsg.status(sysTenantParamService.addTenantParam(sysTenantParamDTO));
    }

    /**
     * 修改租户
     *
     * @param sysTenantParamDTO
     * @return
     */
    @PutMapping
    @PreAuth("sys_tenantParam_edit")
    @OperLog(desc = "修改租户")
    public Result<Void> updateTenantParam(@Validated(UpdateGroup.class) @RequestBody SysTenantParamDTO sysTenantParamDTO){
        return ResponseMsg.status(sysTenantParamService.updateTenantParam(sysTenantParamDTO));
    }

    /**
     * 添加租户
     *
     * @param paramId
     * @return
     */
    @DeleteMapping("/{paramId}")
    @PreAuth("sys_tenantParam_delete")
    @OperLog(desc = "删除租户")
    public Result<Void> deleteTenantParam(@PathVariable String paramId){
        return ResponseMsg.status(sysTenantParamService.deleteTenantParam(paramId));
    }
}
